<?php
class DbFile{
	function __construct($c){
		$this->commands = $c;
	}
	
	public function run($attr){
		if(!isset($attr['db_key']))
			exit('db_key=xxx');
		
		if(!isset($GLOBALS['db_config']))
			exit('db_config is null');
		
		if(!isset($GLOBALS['db_config'][$attr['db_key']]))
			exit('db_key not in db_config');
		
		$db = getDb($attr['db_key']);
		$table = $db->getFields();
		if(!$table)
			exit('table is null');
		
		$br = "\r\n";
		
		$fd = fopen("f:/www/webservice/doc/field.php",'w+');
		$str="<?php\r\nreturn array($br";
		foreach($table as $k=>$fileds){
			$str .= "\t'".$k."'=>array($br";
			foreach($fileds as $k=>$v){
				$str .= "\t\t'name'=>'". $v['COLUMN_NAME'] ."','is_null'=>'{$v['IS_NULLABLE']}','type'=>\"{$v['COLUMN_TYPE']}\",$br";
			}
// 			echo "\n\n";
			$str .= "\t);$br";
		}
		$str .= ");$br";
		fwrite($fd, $str);
	}
}
